// pages/monitor/components/gzhBinding/gzhBinding.ts
import { getWxQRCodeApi, getPushSettingApi } from "../../../../api/monitor"

Component({

  /**
   * 组件的属性列表
   */
  properties: {
    ifBinding: {
      type: String,
      value: ""
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    first: -1,
    stepList: [{ id: 1, title: "步骤1", content: "截屏保存下方“二维码图片”" }, { id: 2, title: "步骤2", content: "打开微信的'扫一扫'" }, { id: 3, title: "步骤3", content: "从“相册”选取二维码图片" }],
    wxQRCodeUrl: "",
    ifBinding: ""
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getWxQRCode() {
      getWxQRCodeApi().then(res => {
        this.setData({ wxQRCodeUrl: res.content })
      })
    },
    getPushSetting() {
      getPushSettingApi().then(res => {
        let binding = res.content.isBiddingWx ? "true" : "false"
        if (binding != this.data.ifBinding) {
          this.handleBack()
        }
      })
    },
    handleBack() {
      wx.navigateBack()
    },
    onChange(e: any) {
      this.setData({ first: e.detail.current });
    }
  },
  lifetimes: {
    attached() {
      this.setData({ ifBinding: this.properties.ifBinding })
      this.getWxQRCode()
    }
  },
  pageLifetimes: {
    show() {
      this.getPushSetting()
    }
  },
})